package com.ljm.sys.org.controller;

import com.ljm.common.dto.BaseResult;
import com.ljm.common.util.ResultUtil;
import com.ljm.shiro.util.UserUtil;
import com.ljm.sys.org.api.SysOrgUserApi;
import com.ljm.sys.org.dto.SysOrgUserDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 系统用户 前端控制器
 * </p>
 *
 * @author HuamingChen
 * @since 2018-12-19
 */
@Api(description="系统用户")
@Controller
@RequestMapping("/org/sysUser")
public class SysOrgUserController {

    /**
     * 系统用户接口
     */
    @Resource
    private SysOrgUserApi iSysUserApi;

    @ApiOperation(value = "保存系统用户")
    @PostMapping(value = "/save")
    @ResponseBody
    @RequiresPermissions({"org:user:add","org:user:edit"})
    public BaseResult save(@ApiParam(value = "系统用户") @RequestBody SysOrgUserDto dto) {
        iSysUserApi.saveData(dto,UserUtil.getUserInfo());
        return ResultUtil.success();
    }

    @ApiOperation(value = "删除系统用户")
    @PostMapping(value = "/del")
    @ResponseBody
    @RequiresPermissions({"org:user:del"})
    public BaseResult del(@ApiParam(value = "主键") @RequestBody List<Long> ids) {
        iSysUserApi.delData(ids);
        return ResultUtil.success();
    }

    @ApiOperation(value = "获取系统用户")
    @GetMapping(value = "/getById")
    @ResponseBody
    @RequiresPermissions({"org:user:view","org:user:edit"})
    public BaseResult getById(@ApiParam(value = "主键") @RequestParam Long id) {
        return ResultUtil.successData(iSysUserApi.getDataById(id));
    }

    @ApiOperation(value = "分页获取系统用户")
    @GetMapping(value = "/getByPage")
    @ResponseBody
    @RequiresPermissions({"org:user:list"})
    public BaseResult getByPage(
            @ApiParam(value = "部门id") @RequestParam(required = false) String fullName,
            @ApiParam(value = "账号") @RequestParam(required = false) String loginName,
            @ApiParam(value = "真实名称") @RequestParam(required = false) String realName,
            @ApiParam(value = "身份证号码") @RequestParam(required = false) String identityNo,
            @ApiParam(value = "邮件") @RequestParam(required = false) String email,
            @ApiParam(value = "页码") @RequestParam Integer pageNo,
            @ApiParam(value = "页大小") @RequestParam Integer pageSize) {
        return ResultUtil.successData(iSysUserApi.getDataByPage(fullName,loginName,realName,identityNo,email,pageNo,pageSize));
    }

    @ApiOperation(value = "获取所有用户")
    @GetMapping(value = "/getAllUser")
    @ResponseBody
    public BaseResult getAllUser() {
        return ResultUtil.successData(iSysUserApi.getAllUser());
    }

}
